package Questions;

/**
 * @version 3 11 February 2013
 * @author Myhaylo Kotsyuruba
 */

public class YesNoQuestions extends Question{

    private boolean answer;
    
    public YesNoQuestions(String text, int score, boolean answer) {
        super(text, score);
        this.answer = answer;
    }
    
    @Override
    public YesNoQuestions clone() {
        return new YesNoQuestions(getText(), getScore(), answer);
    }

    public String toString() {
        String result = String.format("%s%nPlease, type `Y` or `N`.",
                getText());
        return result;
    }
    
    public static Question createQuestion(String data) {
        String[] fields = data.split(FIELDS_SEPARATOR);
        Question newQuestion = new YesNoQuestions(fields[0], 
                Integer.parseInt(fields[1]), Boolean.parseBoolean(fields[2]));
        return newQuestion;
    }

    public int rateUserAnswer(String userAnswer) {
        String markingTrue = "Y";
        if (answer == userAnswer.equalsIgnoreCase(markingTrue)) {
            return getScore();
        }
        return 0;
    }
}
